package cz.myslivec.knihovna.entity;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Table(name="AUTHOR")
//@SequenceGenerator(name="AUTHOR_SEQ", sequenceName="AUTHOR_SEQ", allocationSize = 1)
public class Author implements Serializable {
	private static final long serialVersionUID = 6680992990938102401L;
	
	@Id
	@Column(name = "AUTH_ID")
	@GeneratedValue(strategy=GenerationType.AUTO)
	private long id;

	private String name;
	
	private String surname;
	
	private String title;
	
	private String note;
	
	@ManyToMany(mappedBy="authors")
	private List<Title> wroteBooks;
	
	@ManyToMany(mappedBy="translators")
	private List<Title> translatedBooks;
	
	private boolean writer;
	
	private boolean translator;

	
	// GET & SET
	
	public List<Title> getWroteBooks() {
		return wroteBooks;
	}

	public void setWroteBooks(List<Title> wroteBooks) {
		this.wroteBooks = wroteBooks;
	}

	public List<Title> getTranslatedBooks() {
		return translatedBooks;
	}

	public void setTranslatedBooks(List<Title> translatedBooks) {
		this.translatedBooks = translatedBooks;
	}

	public boolean isWriter() {
		return writer;
	}

	public void setWriter(boolean writer) {
		this.writer = writer;
	}

	public boolean isTranslator() {
		return translator;
	}

	public void setTranslator(boolean translator) {
		this.translator = translator;
	}

	public long getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getSurname() {
		return surname;
	}

	public void setSurname(String surname) {
		this.surname = surname;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getNote() {
		return note;
	}

	public void setNote(String note) {
		this.note = note;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (int) (id ^ (id >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Author other = (Author) obj;
		if (id != other.id)
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Author [id=" + id + ", name=" + name + ", surname=" + surname
				+ ", title=" + title + ", note=" + note + ", wroteBooks="
				+ wroteBooks + ", translatedBooks=" + translatedBooks
				+ ", writer=" + writer + ", translator=" + translator + "]";
	}
}
